//SamXIAO
#include <bits/stdc++.h>
using namespace std;

char s1[1000][103];
int f[1086];

void saveWord(int no, char const *src, int len)
{
	for(int i=0; i<len; i++) s1[no][i] = src[i];
}

void w1()
{
	int cnt = 0, ans = 0, n;
	int ma = -1, mi = 9999, maW, miW, start=0, end=0, wCnt=0;
	string ss;
	getline(cin ,ss);
	int l = ss.length();
	for(int i = 0; i < l; i++){
		char ch = ss.c_str()[i];
		if(' ' == ch || ',' == ch){
			if(cnt){
				saveWord(wCnt++, &ss.c_str()[start], cnt);
			}
			cnt = 0;
			start = i + 1;
		}
		else{
			cnt++;
		}
	}
	if(cnt){
		saveWord(wCnt++, &ss.c_str()[start], cnt);
	}
	for(int i = 0; i < wCnt; i++){
		int l1 =  strlen(s1[i]);
		if(ma < l1) ma = l1, maW = i;
		if(mi > l1) mi = l1,  miW = i;
	}

	printf("%s\n%s", s1[maW], s1[miW]);
}

int main()
{
	w1();
  return 0;
}
